"""
正则表达式
"""
import re


def fun(file_name):
    file_obj = open(file_name)
    str = file_obj.read()
    str = str.replace("\n","")
    str = str.replace("\t","")
    file_obj.close()
    # str = '''<li class="d_name" data-field='{&quot;user_id&quot;:2331746151}'>				 					 	<a data-field='{&quot;un&quot;:&quot;\u732b\u54aa1307&quot;,&quot;id&quot;:&quot;679fe78cabe592aa31333037fb8a&quot;}'alog-group="p_author" class="p_author_name j_user_card" href="/home/main?un=%E7%8C%AB%E5%92%AA1307&ie=utf-8&id=679fe78cabe592aa31333037fb8a&fr=pb&ie=utf-8" target="_blank">桔子柚子草莓<img src="//tb1.bdstatic.com/tb/cms/nickemoji/2-12.png" class="nicknameEmoji" style="width:13px;height:13px"/></a></li>'''
    # 先获取整个内容区域
    content_pattern = r'<div class="p_postlist" id="j_p_postlist">(.*?)</div><div class="right_section right_bright">';
    content_rs = re.findall(content_pattern, str)
    content_div_str = content_rs[0]

    # 获取具体每条item
    pattern = r'<div class="l_post j_l_post l_post_bright noborder "(.*?)</div>'
    content_lst = re.findall(pattern, content_div_str)

    pattern2 = r'content="(.*?)"'

    for temp in content_lst:
        print(temp)

if __name__ == "__main__":
    file_name = "./files/20191019144800.txt"
    fun(file_name)
